﻿// =====================================================================
// <copyright file="LazyList.cs" author="David R. Guindo">
// 	Copyright (C) 2013. All rights reserved.
// </copyright>
// =====================================================================
// This code is released under the terms of the Apache 2.0 license, 
// http://apache.org/licenses/LICENSE-2.0.html
// =====================================================================

namespace AppBlock.Core
{
    using System;
    using System.Collections.Generic;

    public class LazyList<T>
    {
        public LazyList(Func<IList<T>> constructor = null)
        {
            if (constructor != null)
            {
                this.Constructor = constructor;
            }
            else
            {
                this.Constructor = () => new List<T>();
            }
        }

        protected Func<IList<T>> Constructor { get; set; }

        private IList<T> list;

        public IList<T> List
        {
            get { return list ?? (list = this.Constructor.Invoke()); }
        }

        public bool IsValueCreated
        {
            get { return list != null; }
        }
    }
}